package com.woupla.city;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.woupla.model.City;
import com.woupla.model.Region;

@Stateless
public class CityEJB {
	@Inject
	private Logger log;

	@Inject
	private EntityManager em;
	
	public List<Region> findRegionLike(String valueSearch){
		TypedQuery<Region> query =  em.createNamedQuery("findAllRegLike",Region.class);
		//TypedQuery<Region> query =  em.createQuery("Select r from Region r where r.label like 'H%'",Region.class);
		query.setParameter("reg","'"+ valueSearch+"%'");
		query.setMaxResults(20);
		List<Region> regions = query.getResultList();
		return regions;
		
	}
	public Region findRegionLabel(String label){
		TypedQuery<Region> query =  em.createNamedQuery("findRegLabel",Region.class);
		query.setParameter("reg", label);
		return query.getSingleResult();
	}
}
